CREATE TRIGGER trigger_AtrakoAllomas_torol
 ON AtrakoAllomas
     
    instead of  Delete
    AS declare @v Int
     BEGIN  
     
		declare t1 cursor for
    	select feldolgozID From Feldolgoz 
    	where  ( select AtrakoAllomasId  from deleted) =  AtrakoAllomasId
        open t1
		fetch next from t1 into @v
		while @@fetch_status = 0
		begin
				delete from feldolgoz 
				where feldolgozid= @v
		
		fetch next from t1 into @v
			  end
			close t1
		deallocate t1	
        --*************************************************************8
       
       
        declare t1 cursor for
        select SzallitId From Szallit
        where  ( select AtrakoAllomasId  from deleted) =  AtrakoAllomasId
        open t1
		fetch next from t1 into @v
		while @@fetch_status = 0
		begin
        		delete from szallit 
				where SzallitId= @v
		
		fetch next from t1 into @v
			  end
			close t1
		deallocate t1	
        
		Delete From HulladekAtrakoAllomasEllenorzese
		where  ( select AtrakoAllomasId  from deleted)=  AtrakoAllomasId
		
		Delete From AtrakoAllomas
		where  ( select AtrakoAllomasId  from deleted)=  AtrakoAllomasId
end


--set @v = (Select AtrakoAllomasId 
	--from AtrakoAllomas h,Feldolgoz f
	--where h.AtrakoallomasId = f.AtrakoallomasId and h.HulladekLerakoId =  )